<template>
    <!-- 医嘱详情 -->
    <div class="app-container">
        <div class="head-container">
            <div class="head-info">
                <div>
                    <strong>{{ detail.patientInfo.patientName }}</strong>
                </div>
                <div>
                    {{ detail.patientInfo.gender ? '男' : '女' }}
                    {{ detail.patientInfo.age }} 岁
                </div>
                <div>{{ detail.patientInfo.admissionNum }}</div>
            </div>

            {{ dialog.view }}


            <div class="head-btn">
                <el-button :type="showZQTYSOrCCYZ ? 'primary' : 'info'" size="mini" :disabled="!showZQTYSOrCCYZ"
                    @click="clickZQTYS">知情同意书</el-button>
                <el-button :type="showZQTYSOrCCYZ ? 'primary' : 'info'" size="mini" :disabled="!showZQTYSOrCCYZ"
                    @click="clickCCYZ">操舱医嘱</el-button>

                <el-button type="primary" size="mini" @click="clickBack">返回</el-button>
            </div>
        </div>

        <div class="body">
            <div id="right">
                <div id="right-top">
                    <div id="right-top-info">
                        <div><strong>治疗项目明细</strong></div>
                        <div>
                            每次固定治疗时间: &nbsp;
                            <span class="cureTime">{{ detail.adviceTime }}</span>
                            &nbsp;
                            <strong>总金额: &nbsp;&nbsp;<i>{{ detail.totalAmount }}</i>元</strong>
                        </div>
                    </div>

                    <el-table :data="detail.adviceList" style="width: 100%" height="330" highlight-current-row
                        :header-cell-style="{ background: '#eef1f6', color: '#606266' }" fit borders>

                        <el-table-column prop="index" label="序号" align="center" />
                        <el-table-column label="自费" align="center">
                            <template #default="{ row }">
                                <el-checkbox size="mini" :true-label="0" :false-label="1"
                                    :value="row.insuranceType"></el-checkbox>
                            </template>
                        </el-table-column>

                        <el-table-column prop="treatmentName" label="项目名称" align="center" />
                        <el-table-column prop="exePeriod" label="疗程" align="center">
                            <template #default="{ row }">
                                <span>{{ row.exePeriod }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="periodNum" label="疗程次数" align="center">
                            <template #default="{ row }">
                                <span>{{ row.periodNum }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="exeInterval" label="执行间隔" align="center">
                            <template #default="{ row }">
                                <span>{{ row.exeInterval }}&nbsp;天</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="singleNum" label="单次数量" align="center">
                            <template #default="{ row }">
                                <span>{{ row.singleNum }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="dicItemUnitName" label="单位" align="center" />
                        <el-table-column prop="exeDepartmentName" label="执行科室" align="center" />
                        <el-table-column prop="unitPrice" label="单价" align="center" />
                    </el-table>
                </div>

                <div id="right-down">
                    <div id="right-down-info">
                        <div><strong>治疗评估</strong></div>
                    </div>

                    <el-table :data="detail.estimateList" height="330" :cell-style="{ 'text-align': 'center' }"
                        :header-cell-style="{
                            background: '#eef1f6',
                            color: '#606266',
                            textAlign: 'center',
                        }" border>
                        <el-table-column prop="index" label="序号" />
                        <el-table-column label="治疗评估表" prop="estimateName" />
                        <el-table-column label="状态" prop="estimateStates">
                            <template #default="{ row }">
                                <el-tag :type="row.estimateStates ? 'success' : 'warning'" effect="plain">
                                    {{ row.estimateStates ? '已评估' : '未评估' }}
                                </el-tag>
                            </template>
                        </el-table-column>

                        <el-table-column label="操作">
                            <template #default="{ row }">
                                <el-link type="primary" v-show="!row.estimateStates" :disabled="allAdviceStatesAre5"
                                    @click="clickAssess(row)">评估</el-link>

                                <el-link type="success" v-show="row.estimateStates ||
                                    row.estimateId == 3 ||
                                    row.estimateId == 8 ||
                                    row.estimateId == 9" @click="clickDetail(row)">详情</el-link>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>
        </div>

        <el-dialog :visible.sync="dialog.show" :width="dialog.width" destroy-on-close :close-on-click-modal="false"
            top="5vh">

            <informedConsent v-show="dialog.view == 'ZQTYS'" :patientInfo="detail.patientInfo"
                :treatmentInformedInfo="detail.treatmentInformedInfo" :fromHistory="fromHistory" @close="close">
            </informedConsent>

            <CCOrder v-show="dialog.view == 'CCYZ'" :adviceHyperbaricOxygen="detail.adviceHyperbaricOxygen"
                :patientInfo="detail.patientInfo" :fromHistory="fromHistory" @close="close"></CCOrder>
        </el-dialog>
    </div>
</template>

<script>
import { queryOrderDetail } from '@/api/residentPhysician/cureBilling.js'
import informedConsent from '../informedConsent/index.vue'
import CCOrder from '../CCOrder/index.vue'

const assessList = [
    // {
    //     type: 1,
    //     name: '吞咽功能障碍评定',
    //     editRoute: 'SwallowEdit',
    //     detailRoute: 'SwallowView'
    // },
    // {
    //     type: 2,
    //     name: '肺功能和日常生活评定表',
    //     editRoute: 'PulmonaryEdit',
    //     detailRoute: 'PulmonaryView'
    // },
    // {
    //     type: 3,
    //     name: '周围性面神经炎治疗成绩评分表',
    //     editRoute: 'FacialNerveEdit',
    //     detailRoute: 'FacialNerveView'
    // },
    // {
    //     type: 4,
    //     name: '初期康复评定记录表',
    //     editRoute: 'EarlyEdit',
    //     detailRoute: 'EarlyView'
    // },
    // {
    //     type: 5,
    //     name: '中期康复评定记录表',
    //     editRoute: 'MidTermEdit',
    //     detailRoute: 'MidTermView'
    // },
    // {
    //     type: 6,
    //     name: '出院前康复评定记录表',
    //     editRoute: 'DischargeEdit',
    //     detailRoute: 'DischargeView'
    // },
    // {
    //     type: 7,
    //     name: '偏瘫运动功能评定表',
    //     editRoute: 'HemiplegiaEdit',
    //     detailRoute: 'HemiplegiaView'
    // },
    // {
    //     type: 8,
    //     name: '神经损伤功能评定表',
    //     editRoute: 'NerveInjuryEdit',
    //     detailRoute: 'NerveInjuryView'
    // },
    // {
    //     type: 9,
    //     name: '神经康复综合评定表',
    //     editRoute: 'NeurorehabilitationEdit',
    //     detailRoute: 'NeurorehabilitationView'
    // },
    // {
    //     type: 10,
    //     name: '感知能力-耳聋分级',
    //     editRoute: 'DeafGradeEdit',
    //     detailRoute: 'DeafGradeView'
    // },
    // {
    //     type: 11,
    //     name: '感知能力-程度评估',
    //     editRoute: 'DegreeEdit',
    //     detailRoute: 'DegreeView'
    // },
    // {
    //     type: 12,
    //     name: '运动能力',
    //     editRoute: 'MotionEdit',
    //     detailRoute: 'MotionView'
    // }
    {
        name: "针灸医疗记录单",
        editRoute: "acupunctureTemplate",
        detailRoute: "acupunctureTemplate",
        type: 13
    },
    {
        name: "康复治疗记录单",
        editRoute: "rehabRecordTemplate",
        detailRoute: "rehabRecordTemplate",
        type: 14
    },
    {
        name: "临床康复介入医疗记录单",
        editRoute: "clinicalRecordTemplate",
        detailRoute: "clinicalRecordTemplate",
        type: 15
    },
    {
        name: "滨江高压氧治疗的心理护理及安全告知书",
        editRoute: "hyperbaricNoticeBJTemplate",
        detailRoute: "hyperbaricNoticeBJTemplate",
        type: 16
    },
    {
        name: "高压氧治疗的心理护理及安全告知书",
        editRoute: "hyperbaricNoticeTemplate",
        detailRoute: "hyperbaricNoticeTemplate",
        type: 17
    },
    {
        name: "舱内治疗评估",
        editRoute: "chamberEvalTemplate",
        detailRoute: "chamberEvalTemplate",
        type: 18
    },
]
export default {
    data() {
        return {
            fromHistory: false,
            showZQTYSOrCCYZ: false,
            estimateId: null,
            detailParams: null,
            batchId: null,  //批号
            allAdviceStatesAre5: false,
            detail: {   //医嘱详情
                patientInfo: {
                    patientId: 0,
                    patientName: "",
                    age: 0,
                    patientType: 0,
                    gender: 0,
                    bedNum: "",
                    admissionNum: "",
                    outpatientNum: ""
                },
                adviceList: [{
                    adviceStates: 0,
                    treatmentName: "",
                    index: 0,
                    adviceId: 0,
                    treatmentId: 0,
                    insuranceType: 0,
                    exePeriod: 0,
                    periodNum: 0,
                    exeInterval: 0,
                    dicExeInterval: 0,
                    singleNum: 0,
                    dicItemUnit: "",
                    dicItemUnitName: "",
                    exeDepartmentCode: "",
                    exeDepartmentName: "",
                    unitPrice: 0
                }],
                adviceTime: "",
                totalAmount: 0,
                estimateList: [{
                    index: 0,
                    estimateId: 0,
                    estimateName: "",
                    estimateStates: 0
                }],
                treatmentInformedInfo: {
                    informedInfoId: 0,
                    signName: "",
                    treatmentTarget: "",
                    dicPatientRelation: "",
                    coreRisk: "",
                    fingerprint: ""
                },
                adviceHyperbaricOxygen: {
                    hyperbaricOxygenId: 0,
                    adviceNote: "",
                    gaugePressure: 0,
                    singleOxygenMinute: 0,
                    singleOxygenNum: 0,
                    intervalOxygenMinute: 0,
                    intervalOxygenNum: 0,
                    exePeriod: 0,
                    periodNum: 0,
                    doctorSign: "",
                    curativeEffect: 0,
                    treatmentInterruptionReason: 0,
                    briefCondition: ""
                }
            },
            dialog: {  //dialog相关参数
                show: false,
                width: '60%',
                view: ''
            },
        };
    },
    components: {
        informedConsent, CCOrder
    },
    methods: {
        //关闭dialog
        close() {
            this.dialog = {
                show: false,
                width: '60%',
                view: ''
            };
        },
        //获取医嘱详情
        getOrderDetail() {
            if (!this.batchId) {
                return;
            }
            queryOrderDetail({ batchId: this.batchId }).then(response => {
                let { code, content } = response;
                if (code === 0 && content) {
                    this.showZQTYSOrCCYZ = content.adviceList.find(item => item.highOxygenStates == 1) ? true : false;
                    this.detail = content;
                    this.allAdviceStatesAre5 = this.detail.adviceList.every(item => item.adviceStates == 5);
                }
            }).catch(err => {
                console.log(err);
                this.$notify({
                    title: '提示',
                    message: '网络出差了,请稍后再试',
                    type: 'danger'
                });
            })
        },
        //点击评估
        clickAssess(row) {
            if (!this.batchId) {
                this.$notify({ title: '提示', message: '请先保存后再进行评估', type: 'warning' });
                return;
            }
            let target = assessList.find(item => item.type == row.estimateId);

            if (target) {
                this.$router.push({ name: target.editRoute, query: { type: 0, source: 1, id: this.batchId } })
            } else {
                console.log(target, "该表目前未对接接口，已经被隐藏，需要重新走数据，这是一个老数据");
            }
        },
        //点击详情
        clickDetail(row) {
            let target = assessList.find(item => item.type == row.estimateId);
            this.$router.push({ name: target.detailRoute, query: { type: 1, source: 1, id: this.batchId } })
        },

        //点击知情同意书
        clickZQTYS() {
            this.dialog = {
                show: true,
                width: '50%',
                view: 'ZQTYS'
            };
        },
        //点击操舱医嘱
        clickCCYZ() {
            this.dialog = {
                show: true,
                width: '50%',
                view: 'CCYZ'
            };
        },
        //点击返回
        clickBack() {
            this.$router.back();
        },

    },
    mounted() {
        this.batchId = this.$route.params.batchId;
        this.getOrderDetail();

    },
};

</script>

<style lang='scss' scoped>
.app-container {
    background-color: #fff;
    padding-bottom: 0;

    .width-80 {
        width: 80px;
    }

    .width-120 {
        width: 120px;
    }

    .width-150 {
        width: 150px;
    }

    .width-180 {
        width: 180px;
    }


    .head-container {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .head-info {
            display: flex;
            justify-content: start;
            align-items: center;
        }

        .head-info>div {
            margin: 0 15px;
        }

        .head-btn {
            .el-button {
                margin: 0 10px;
            }
        }
    }

    .body {
        width: 100%;
        height: 800px;
        max-height: 800px;
        box-sizing: border-box;
        padding-bottom: 10px;
        border: 1px solid #ccc;
        display: flex;

        #right {
            width: 100%;
            padding: 10px 20px;

            #right-top {
                width: 100%;
                border-bottom: 1px solid #ccc;
                margin-bottom: 20px;

                #right-top-info {
                    height: 38px;
                    padding: 0 0 10px;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    .cureTime {
                        margin: 0 20px;
                    }

                    i {
                        font-style: normal;
                        color: red;
                    }
                }
            }

            #right-down {
                width: 100%;

                #right-down-info {
                    height: 38px;
                    padding: 0 0 10px;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                }

                .el-link {
                    margin: 0 10px;
                }
            }
        }
    }
}
</style>
